package com.mach.platform.repository;

import com.mach.platform.domain.ProductionOrder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface ProductionOrderRepo extends BaseRepository<ProductionOrder> {

    @Query(value = "select * from production_order where " +
            "if(?1 !='',DATE_FORMAT(`time`,'%Y-%m-%d')=?1,1=1) and if(?2 !='',class_ban=?2,1=1)",
            countQuery = "select count(*) from production_order where " +
                    "if(?1 !='',DATE_FORMAT(`time`,'%Y-%m-%d')=?1,1=1) and if(?2 !='',class_ban=?2,1=1)",nativeQuery = true)
    Page<ProductionOrder> getByTimeAndClassBan(String time, String classBan, Pageable pageable);

    @Query(value = "select * from production_order where " +
            "if(?1 !='',DATE_FORMAT(`time`,'%Y-%m-%d')=?1,1=1) and if(?2 !='',class_ban=?2,1=1)",nativeQuery = true)
    List<ProductionOrder> getDataByTimeAndClassBan(String time, String classBan);
}
